$(function() {
	//搜索并展开左侧
	$(".sp_sch_btn").on("click", function() {
		$(".spl_res").addClass("spl_show")
		$(".spl_abtn span").html("<")
	})
	//左侧展开收缩按钮事件
	$(".spl_abtn").on("click", function() {
		if ($(".spl_res").hasClass("spl_show")) {
			$(".spl_res").removeClass("spl_show")
			$(".spl_abtn span").html(">")
		} else {
			$(".spl_res").addClass("spl_show")
			$(".spl_abtn span").html("<")
		}
	})
	//警务资源-定位展示
	$(".sp_sch_item").on("click", function() {
		$(this).addClass("sec").siblings(".sp_sch_item").removeClass("sec")
		$(".sp_sch_select>label").attr("class", $(this).data("class"))
	})
	//地图场景切换
	$(".spr_at_qh_img").on("click", function() {
		if ($(".spr_at_qh_con").hasClass("spr_at_qh_show")) {
			$(".spr_at_qh_con").removeClass("spr_at_qh_show")
			$(".spr_at_qh").removeClass("spr_at_qh_left")
		} else {
			$(".spr_at_qh_con").addClass("spr_at_qh_show")
			$(".spr_at_qh").addClass("spr_at_qh_left")
		}
	})
	//地图场景切换
	$(".spr_at_qh_img1").on("click", function() {
		if ($(".spr_at_qh_con1").hasClass("spr_at_qh_show")) {
			$(".spr_at_qh_con1").removeClass("spr_at_qh_show")
			$(".spr_at_qh1").removeClass("spr_at_qh_left1")
		} else {
			$(".spr_at_qh_con1").addClass("spr_at_qh_show")
			$(".spr_at_qh1").addClass("spr_at_qh_left1")
		}
	})


	$(".spr_at_qh_item").on("click", function() {
		$(this).addClass("sec").siblings(".spr_at_qh_item").removeClass("sec")
	})
	$(".spr_at_qh_item1").on("click", function() {
		if ($(this).hasClass("sec")) {
			$(this).removeClass("sec");
		} else {
			$(this).addClass("sec");
		}

	})

	//点击图标显示窗口
	$(".sp_icons_hover").on("click", function() {
		if ($(this).hasClass("sp_icons_click")) {
			$(".sp_icons_hover").removeClass("sp_icons_click")
			$(".gdglr_top").hide()
			$(".gdglr_btm").hide()
		} else {
			$(".sp_icons_hover").removeClass("sp_icons_click")
			$(this).addClass("sp_icons_click")
			$(".gdglr_top").css("display", "flex")
			$(".gdglr_btm").show()
		}
	})
	//工地点击初始化
	function gdinof() {
		$.ajax({
			type: 'get',
			dataType: "json",
			data: {},
			url: GDUrl + "/VIAS/web/snapshot/WorkSite/buildingDevice",
			success: function(data) {
				if (data.length > 0) {
					$.each(data, function(i, row) {
						if (i == 0) {
							$("#zwgdLs").attr("gid", row.siteName);

							$("#zwgdLs").attr("devid", row.deviceArr);
						}
					})
				}
			}
		});
	}

	function getCenterPoint(lons, lats) {
		var minLng = Math.min(...lons);
		var maxLng = Math.max(...lons);
		var minLat = Math.min(...lats);
		var maxLat = Math.max(...lats);
		var cenLng = (parseFloat(maxLng) + parseFloat(minLng)) / 2;
		var cenLat = (parseFloat(maxLat) + parseFloat(minLat)) / 2;
		return new BMap.Point(cenLng, cenLat);
	}
	gdinof();
	$("#zwgdLs").click(function() {

		$.ajax({
			type: "get",
			dataType: "json",
			async: false,
			data: {
				id: $("#zwgdLs").attr("gid")
			},
			url: GDUrl + '/VIAS/web/snapshot/WorkSite/querySiteById',
			success: function(data) {
				var lons = [];
				var lats = [];
				if (data[0].SHAPE != null) {
					var coordinates = JSON.parse(data[0].SHAPE);
					$.each(coordinates.coordinates[0], function(i, lonlat) {
						lon = lonlat[0]; //经度坐标
						lat = lonlat[1]; //纬度坐标
						lons.push(lon);
						lats.push(lat);
						// 创建信息窗口对象

					});
					po = getCenterPoint(lons, lats)
				} else if (data[0].JWD != null && data[0].JWD != "") {
					p = data[0].JWD.split(",");
					po = new BMap.Point(p[1], p[0]);
				}
				var row = data[0]
				var newin = window.open();
				newin.location.href = "/ditu/detail1.html" + "?gdid=" + row.ID + "&point=" + po.lat + "," + po.lng;
			}
		})
	});
	$("#spkLs").click(function() {
		layui.use('layer', function() {
			var layer = layui.layer;
			layer.open({
				type: 2,
				fixed: true,
				title: ['卡口详情 <span style="font-size:15px">' + '24042 前屯路与后屯路交叉口' + '</span>',
					'font-size: 22px;color: rgb(49, 70, 89);'
				],
				closeBtn: 1,
				scrollbar: false,
				maxmin: false,
				content: 'jiaotong/shishiSP1.html?deviceId=11010824001320024042',
				area: ['50%', '65%'],
				cancel: function(index, layero) {
					stopflvwkk();
				}
			});
		});

	});
	$("#wkkLs").click(function() {
		layui.use('layer', function() {
			var layer = layui.layer;
			layer.open({
				type: 2,
				fixed: true,
				title: ['卡口详情 <span style="font-size:15px">' + '28172 翠湖北路与稻香湖交叉路口' + '</span>',
					'font-size: 22px;color: rgb(49, 70, 89);'
				],
				closeBtn: 1,
				scrollbar: false,
				maxmin: false,
				content: 'jiaotong/shishiSP.html?deviceId=11010828001320028172',
				area: ['100%', '100%'],
				cancel: function(index, layero) {
					stopflvwkk();
				}
			});
		});
	});
	initCondition();
	//初始化layui
	function initCondition() {
		var today = new Date().pattern("yyyy-MM-dd 00:00:00");
		var endDay = new Date();


		layui.use('laydate', function() {
			var laydate = layui.laydate;
			laydate.render({
				elem: '#startTime',
				type: 'datetime',
				theme: '#2180d4',
				value: today,
				btns: ['now', 'confirm'],
				max: new Date().pattern("yyyy-MM-dd HH:mm:ss"),
				done: function(value, date) {
					var starttime = value.replace(/-/g, "/"),
						d1 = (new Date(starttime)).getTime(),
						endtime = ($("#endTime").val()).replace(/-/g, "/"),
						d2 = (new Date(endtime)).getTime();
					if (d1 > d2) {
						$("#endTime").val('');
					}
					enddate.config.min = laydatechange(date);
				}
			});
			var enddate = laydate.render({
				elem: '#endTime',
				type: 'datetime',
				theme: '#2180d4',
				value: endDay,
				btns: ['now', 'confirm'],
				min: 0
			});
		});



	}
});

function initCondition() {
	var today = new Date().pattern("yyyy-MM-dd 00:00:00");
	var endDay = new Date();


	layui.use('laydate', function() {
		var laydate = layui.laydate;
		laydate.render({
			elem: '#startTime',
			type: 'datetime',
			theme: '#2180d4',
			value: today,
			btns: ['now', 'confirm'],
			max: new Date().pattern("yyyy-MM-dd HH:mm:ss"),
			done: function(value, date) {
				var starttime = value.replace(/-/g, "/"),
					d1 = (new Date(starttime)).getTime(),
					endtime = ($("#endTime").val()).replace(/-/g, "/"),
					d2 = (new Date(endtime)).getTime();
				if (d1 > d2) {
					$("#endTime").val('');
				}
				enddate.config.min = laydatechange(date);
			}
		});
		var enddate = laydate.render({
			elem: '#endTime',
			type: 'datetime',
			theme: '#2180d4',
			value: endDay,
			btns: ['now', 'confirm'],
			min: 0
		});
	});

	

}
